package cn.net.xyan.kotlin

import com.fasterxml.jackson.annotation.JsonView
import com.fasterxml.jackson.core.Version
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.module.SimpleModule
import org.junit.Test
import java.math.BigDecimal
import java.util.*

/**
 * Created by zarra on 2017/3/23.
 */

data class TestDataCls(var name:String){
    var code:String = ""

    var n: Int = 1

    @JsonSerialize(using = MoneySerializer::class)
    var bd :BigDecimal = BigDecimal.valueOf(1.43432423)
}

class JsonTest{

    companion object{
        fun mapper():ObjectMapper{
            val mapper = ObjectMapper()
            val simpleModule = SimpleModule("SimpleModule",
                    Version(1, 0, 0, null,null,null))
           // simpleModule.addSerializer(TestDataCls::class.java,ObjectSerializer())
            mapper.registerModule(simpleModule)

            return mapper
        }
    }

    @Test
    fun test1():Unit{
        val om = mapper()

        val v = TestDataCls("a")

        var json = om.writeValueAsString(v)

        println("v:$json")



        val jc = JavaClass()

        jc.propertyB = "a"

        val t = TransferObject("test",v)

        println(om.writeValueAsString(t))

    }
}